package cn.com.startai.smartadh5.db.db.gen;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import cn.com.startai.smartadh5.db.db.entity.Screen;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "SCREEN".
*/
public class ScreenDao extends AbstractDao<Screen, Long> {

    public static final String TABLENAME = "SCREEN";

    /**
     * Properties of entity Screen.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property BtId = new Property(1, Long.class, "btId", false, "BT_ID");
        public final static Property Sid = new Property(2, String.class, "sid", false, "SID");
        public final static Property Times = new Property(3, String.class, "times", false, "TIMES");
        public final static Property Start = new Property(4, java.util.Date.class, "start", false, "START");
        public final static Property End = new Property(5, java.util.Date.class, "end", false, "END");
        public final static Property Priority = new Property(6, String.class, "priority", false, "PRIORITY");
        public final static Property Utype = new Property(7, String.class, "utype", false, "UTYPE");
        public final static Property Size = new Property(8, String.class, "size", false, "SIZE");
        public final static Property Layout = new Property(9, String.class, "layout", false, "LAYOUT");
        public final static Property NewLine = new Property(10, boolean.class, "newLine", false, "NEW_LINE");
        public final static Property AppsRelation = new Property(11, String.class, "appsRelation", false, "APPS_RELATION");
        public final static Property Content = new Property(12, String.class, "content", false, "CONTENT");
    }

    private DaoSession daoSession;

    private Query<Screen> broadcastTable_ScreensQuery;

    public ScreenDao(DaoConfig config) {
        super(config);
    }
    
    public ScreenDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = daoSession;
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"SCREEN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"BT_ID\" INTEGER," + // 1: btId
                "\"SID\" TEXT," + // 2: sid
                "\"TIMES\" TEXT," + // 3: times
                "\"START\" INTEGER," + // 4: start
                "\"END\" INTEGER," + // 5: end
                "\"PRIORITY\" TEXT," + // 6: priority
                "\"UTYPE\" TEXT," + // 7: utype
                "\"SIZE\" TEXT," + // 8: size
                "\"LAYOUT\" TEXT," + // 9: layout
                "\"NEW_LINE\" INTEGER NOT NULL ," + // 10: newLine
                "\"APPS_RELATION\" TEXT," + // 11: appsRelation
                "\"CONTENT\" TEXT);"); // 12: content
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SCREEN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, Screen entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Long btId = entity.getBtId();
        if (btId != null) {
            stmt.bindLong(2, btId);
        }
 
        String sid = entity.getSid();
        if (sid != null) {
            stmt.bindString(3, sid);
        }
 
        String times = entity.getTimes();
        if (times != null) {
            stmt.bindString(4, times);
        }
 
        java.util.Date start = entity.getStart();
        if (start != null) {
            stmt.bindLong(5, start.getTime());
        }
 
        java.util.Date end = entity.getEnd();
        if (end != null) {
            stmt.bindLong(6, end.getTime());
        }
 
        String priority = entity.getPriority();
        if (priority != null) {
            stmt.bindString(7, priority);
        }
 
        String utype = entity.getUtype();
        if (utype != null) {
            stmt.bindString(8, utype);
        }
 
        String size = entity.getSize();
        if (size != null) {
            stmt.bindString(9, size);
        }
 
        String layout = entity.getLayout();
        if (layout != null) {
            stmt.bindString(10, layout);
        }
        stmt.bindLong(11, entity.getNewLine() ? 1L: 0L);
 
        String appsRelation = entity.getAppsRelation();
        if (appsRelation != null) {
            stmt.bindString(12, appsRelation);
        }
 
        String content = entity.getContent();
        if (content != null) {
            stmt.bindString(13, content);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, Screen entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Long btId = entity.getBtId();
        if (btId != null) {
            stmt.bindLong(2, btId);
        }
 
        String sid = entity.getSid();
        if (sid != null) {
            stmt.bindString(3, sid);
        }
 
        String times = entity.getTimes();
        if (times != null) {
            stmt.bindString(4, times);
        }
 
        java.util.Date start = entity.getStart();
        if (start != null) {
            stmt.bindLong(5, start.getTime());
        }
 
        java.util.Date end = entity.getEnd();
        if (end != null) {
            stmt.bindLong(6, end.getTime());
        }
 
        String priority = entity.getPriority();
        if (priority != null) {
            stmt.bindString(7, priority);
        }
 
        String utype = entity.getUtype();
        if (utype != null) {
            stmt.bindString(8, utype);
        }
 
        String size = entity.getSize();
        if (size != null) {
            stmt.bindString(9, size);
        }
 
        String layout = entity.getLayout();
        if (layout != null) {
            stmt.bindString(10, layout);
        }
        stmt.bindLong(11, entity.getNewLine() ? 1L: 0L);
 
        String appsRelation = entity.getAppsRelation();
        if (appsRelation != null) {
            stmt.bindString(12, appsRelation);
        }
 
        String content = entity.getContent();
        if (content != null) {
            stmt.bindString(13, content);
        }
    }

    @Override
    protected final void attachEntity(Screen entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public Screen readEntity(Cursor cursor, int offset) {
        Screen entity = new Screen( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1), // btId
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // sid
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // times
            cursor.isNull(offset + 4) ? null : new java.util.Date(cursor.getLong(offset + 4)), // start
            cursor.isNull(offset + 5) ? null : new java.util.Date(cursor.getLong(offset + 5)), // end
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // priority
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // utype
            cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // size
            cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // layout
            cursor.getShort(offset + 10) != 0, // newLine
            cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // appsRelation
            cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12) // content
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, Screen entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setBtId(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1));
        entity.setSid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setTimes(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setStart(cursor.isNull(offset + 4) ? null : new java.util.Date(cursor.getLong(offset + 4)));
        entity.setEnd(cursor.isNull(offset + 5) ? null : new java.util.Date(cursor.getLong(offset + 5)));
        entity.setPriority(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setUtype(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setSize(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
        entity.setLayout(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
        entity.setNewLine(cursor.getShort(offset + 10) != 0);
        entity.setAppsRelation(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11));
        entity.setContent(cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(Screen entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(Screen entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(Screen entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "screens" to-many relationship of BroadcastTable. */
    public List<Screen> _queryBroadcastTable_Screens(Long btId) {
        synchronized (this) {
            if (broadcastTable_ScreensQuery == null) {
                QueryBuilder<Screen> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.BtId.eq(null));
                broadcastTable_ScreensQuery = queryBuilder.build();
            }
        }
        Query<Screen> query = broadcastTable_ScreensQuery.forCurrentThread();
        query.setParameter(0, btId);
        return query.list();
    }

}
